define(function(require, exports, module) {
    var config;
    function autoImg() {
        $('.dog-photo .thumbnail img').each(function() {
            var obj = $(this);
            var src = obj.attr('data-src');
            if (!src) {
                return;
            }
            var img = new Image();
            img.onload = function() {
                obj.attr('src', src);
                var w = obj.width();
                var h = obj.height();
                if (w >= h) {
                    obj.css({'height': '100%'});
                } else {
                    obj.css({'width': '100%'});
                }
            }
            img.src = src;
        });
    }

    function bindEditPhoto() {
        $('.js-edit-btn').on('click', function() {
            var src = $(this).closest('.thumbnail').find('.js-user-photo').attr('src');
            var id = $(this).closest('.thumbnail').attr('photoId');
            var titleObj = $(this).closest('.thumbnail').find('.js-title');
            var descObj = $(this).closest('.thumbnail').find('.js-desc');
            var title = titleObj ? titleObj.html() : '';
            var desc = descObj ? descObj.html() : '';
            require.async('photo', function(a) {
                a.showEdit(src, '', id, title, desc);
            });
        });
    }

    exports.init = function(c) {
        config = c;
        autoImg();
        bindEditPhoto();
        require.async('./TopInfo', function(a) {
            a.init(c);
        });
    }
});